import UnoCss from 'unocss/vite';
import { presetUno, presetAttributify, presetIcons } from 'unocss';

export default () => {
  return UnoCss({
    presets: [presetUno(), presetAttributify(), presetIcons()],
    rules: [
      [/^f-(\d+)$/, (match) => ({ 'font-size': `${+match[1]}px` })],
      [/^p-(\d+)$/, (match) => ({ padding: `${+match[1]}px` })],
      [/^p-r-(\d+)-(\d+)$/, (match) => ({ 'padding-left': `${+match[1]}px`, 'padding-right': `${+match[2]}px` })],
      [/^p-c-(\d+)-(\d+)$/, (match) => ({ 'padding-top': `${+match[1]}px`, 'padding-bottom': `${+match[2]}px` })],
      [/^p-z$/, () => ({ 'padding': `0 !important` })],
      [/^m-r-(\d+)-(\d+)$/, (match) => ({ 'margin-left': `${+match[1]}px`, 'margin-right': `${+match[2]}px` })],
      [/^m-c-(\d+)-(\d+)$/, (match) => ({ 'margin-top': `${+match[1]}px`, 'margin-bottom': `${+match[2]}px` })],
      [/^m-z$/, () => ({ 'margin': `0 !important` })],
      [/^vh-(\d+)$/, (match) => ({ 'height': `${+match[1]}vh !important` })],
      [/^xh-(\d+)$/, (match) => ({ 'height': `${+match[1]}px !important` })],
      [/^rh-(\d+)$/, (match) => ({ 'height': `${+match[1]}% !important` })],
      [/^vw-(\d+)$/, (match) => ({ 'width': `${+match[1]}vw !important` })],
      [/^xw-(\d+)$/, (match) => ({ 'width': `${+match[1]}px !important` })],
      [/^xw-l-(\d+)$/, (match) => ({ 'width': `calc(100% - ${+match[1]}px) !important` })],
      [/^rw-(\d+)$/, (match) => ({ 'width': `${+match[1]}% !important` })],
    ],
    shortcuts: {
      'panel-title':
        'pb-[5px] font-sans leading-[1.1] font-medium text-base text-[#6379bb] border-b border-b-solid border-[var(--el-border-color-light)] mb-5 mt-0'
    },
    hmrTopLevelAwait: false // unocss默认是true，低版本浏览器是不支持的，启动后会报错
  });
};
